<?php

//var_dump();
class DuomaiGoodsSite extends BaseModel
{
    public $res;
    public $redis_key = "";

    public function getSource()
    {
        return "duomai_goods_site";
    }

    public function initialize()
    {
        parent::initialize();
    }

    public function get_list($params)
    {
        $condition = "";
        if (isset($params['keywords']) && !empty($params['keywords'])) {
            $condition = "site_description like '%{$params['keywords']}%' or ads_id = '{$params['keywords']}'";
        }
        $page = isset($params['page']) ? intval($params['page']) : 1;
        $size = isset($params['limit']) ? intval($params['limit']) : 10;

        if ($page > 0) {
            $page = ($page - 1) * $size;
        }

        $cate_list       = $this->find(
            array(
                $condition,
                'order'  => 'ads_id asc',
                'limit'  => $size,
                'offset' => $page
            ))->toarray();
        $result['total'] = $this->count($condition);
        $result['list']  = $cate_list;
        return $result;
    }

    /**
     * 多麦站点列表
     */
    public function getlistsite($type = 0, $data = [])
    {
        if ($type) {
            $conditions = "status=3 and cate_id={$type}";
        } else {
            $conditions = "status=3";
        }
        if (isset($data['keyword']) && !empty($data['keyword'])) {
            $conditions .= " and (cate_name like '%{$data['keyword']}%') or (name like '%{$data['keyword']}%')";
        }
        $res = $this->find(array(
            $conditions,
            'columns' => 'id,site_url,site_logo,name,cate_name,cate_id,ads_commission,diy_commission,ads_id'
        ));
        return $res;
    }


    /**
     * 根据订单号查找记录
     */
    public function find_by_order_sn($order_sn)
    {
        return $this->findFirstByOrderSn($order_sn);
    }


    //根据站点地址，查找记录
    public function find_by_site_url($site_url)
    {
        return $this->findFirstBySiteUrl($site_url);
    }

}
